const fs = require('fs');
const path = require('path');
const config = require('./config')
const { getDataByFields, checkHttpRequestHasBody } = require('./utils')

let requestParamsCheckTpl;



const schemaValidator = fs.readFileSync(
  path.resolve(__dirname, './code/schemaValidator.js'),
  'utf8'
);

module.exports = function genCode(interfaceList) {
  let interfaceListCode = ''
  let res_body_list = ''
  interfaceList.forEach((interfaceData, index) => {
    interfaceListCode += `[\`${interfaceData.method} \${path}${interfaceData.path}\`]: interface.${config.methodName(interfaceData.path, interfaceData.method)}, //${interfaceData.title}  \n  `
    res_body_list += `${config.methodName(interfaceData.path, interfaceData.method)}:${JSON.stringify(interfaceData.res_body)}, \n`
  });
  let code = config.globalCode || '';
  code = `
 
  const path = ${config.prefixPath || '\'\''}
  const interface = createData()
  module.exports = {
    ${interfaceListCode}
  }
  function createData(){
    return {
      ${res_body_list}
    }
  }
    `;
  return code
}